package com.splic.product.service.impl;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import com.splic.common.utils.DateUtils;
import com.splic.product.dto.HolidayVacationsRequestDto;
import com.splic.product.service.impl.thirdRequest.HolidayVacationsRequestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.HolidayVacationsMapper;
import com.splic.product.domain.HolidayVacations;
import com.splic.product.service.HolidayVacationsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 节假日Service业务层处理
 * 
 * @author singe
 * @date 2022-01-04
 */
@Service
public class HolidayVacationsServiceImpl implements HolidayVacationsService
{
    @Autowired
    private HolidayVacationsMapper holidayVacationsMapper;
    @Autowired
    private HolidayVacationsRequestServiceImpl holidayVacationsRequestServiceImpl;

    /**
     * 查询节假日
     * 
     * @param id 节假日主键
     * @return 节假日
     */
    @Override
    public HolidayVacations selectHolidayVacationsById(Long id)
    {
        return holidayVacationsMapper.selectHolidayVacationsById(id);
    }

    /**
     * 查询节假日列表
     * 
     * @param holidayVacations 节假日
     * @return 节假日
     */
    @Override
    public List<HolidayVacations> selectPageList(HolidayVacations holidayVacations)
    {
        return holidayVacationsMapper.selectHolidayVacationsList(holidayVacations);
    }

    /**
     * 查询节假日列表
     *
     * @param holidayVacations 节假日
     * @return 节假日
     */
    @Override
    public List<HolidayVacations> selectHolidayVacationsList(HolidayVacations holidayVacations)
    {
        return holidayVacationsMapper.selectHolidayVacationsList(holidayVacations);
    }

    /**
     * 新增节假日
     * 
     * @param holidayVacations 节假日
     * @return 结果
     */
    @Override
    public int insert(HolidayVacations holidayVacations)
    {
        holidayVacations.setCreateTime(DateUtils.getNowDate());
        return holidayVacationsMapper.insert(holidayVacations);
    }

    /**
     * 修改节假日
     * 
     * @param holidayVacations 节假日
     * @return 结果
     */
    @Override
    public int update(HolidayVacations holidayVacations)
    {
        holidayVacations.setUpdateTime(DateUtils.getNowDate());
        return holidayVacationsMapper.update(holidayVacations);
    }


    /**
     * 删除节假日信息
     * 
     * @param id 节假日主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        return holidayVacationsMapper.deleteById(id);
    }
    /**
     * 修改节假日
     *
     * @param holidayVacations 节假日信息
     * @return 结果
     */
    @Override
    @Transactional
    public int saveOrUpdate(HolidayVacations holidayVacations)
    {
        if(holidayVacations.getId() != null){
            holidayVacations.setUpdateTime(new Date());
            return holidayVacationsMapper.update(holidayVacations);
        }else{
            holidayVacations.setCreateTime(new Date());
            return holidayVacationsMapper.insert(holidayVacations);
        }
    }

    @Override
    public void requestThirdData() {
        holidayVacationsRequestServiceImpl.requestThirdData();
    }
}
